#include "exio.h"
#include "esp_log.h"
#include "../hal_config.h"
#include "driver/i2c_master.h"
#include "esp_io_expander_tca9554.h"

const char* HAL_EXIO_TAG = "EXIO";

esp_io_expander_handle_t hal_io_expander = NULL;

void hal_exio_init(void) {
    ESP_LOGI(HAL_EXIO_TAG, "Initializing EXIO bus...");

    // I2C 总线句柄
    i2c_master_bus_handle_t i2c_bus_handle = NULL;
    i2c_master_get_bus_handle(PIN_I2C_PROT, &i2c_bus_handle);
    //
    ESP_ERROR_CHECK(esp_io_expander_new_i2c_tca9554(i2c_bus_handle, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000, &hal_io_expander));

    ESP_LOGI(HAL_EXIO_TAG, "EXIO bus initialized.");
}
